package com.gps.funnymath.abstractItems;

import com.gps.funnymath.concreteItems.ConcreteToken;
import com.gps.funnymath.domains.UnitDomain;


public class AbstractUnit implements AbstractToken {

	UnitDomain unitDomain;
	ConcreteToken lastConcreteToken;
	
	public AbstractUnit(UnitDomain unitDomain){
		this.unitDomain = unitDomain;
		lastConcreteToken = null;
	}

	public ConcreteToken instantiate(){
		lastConcreteToken = unitDomain.getRandom();
		return unitDomain.getRandom();
	}
	
	@Override
	public ConcreteToken getLastInstantiation() {
		return lastConcreteToken;
	}
	
	@Override
	public ConcreteToken getConcreteToken() {
		if(lastConcreteToken != null)
			return lastConcreteToken;

		return instantiate();
	}
	
	@Override
	public void clearInstantiationReferences() {
		lastConcreteToken = null;
	}
	
}
